import 'package:chat/screen/large_background_image.dart';
import 'package:chat/screen/message_list_screen.dart';
import 'package:flutter/material.dart';

class TabScreen extends StatelessWidget {
  const TabScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return const Scaffold(body: BottomNavigationBarDemo());
  }
}

class BottomNavigationBarDemo extends StatefulWidget {
  const BottomNavigationBarDemo({super.key});

  @override
  State<BottomNavigationBarDemo> createState() => _BottomNavigationBarDemoState();
}

class _BottomNavigationBarDemoState extends State<BottomNavigationBarDemo> {
  int _selectedIndex = 0; // 将状态变量移到类内部

  static final List<Widget> _widgetOptions = <Widget>[
    const LargeBackgroundImage(),
    const MessageListScreen(),
    const MessageListScreen(),
    const MessageListScreen(),
  ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(index: _selectedIndex, children: _widgetOptions),
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.check_circle), label: ''),
          BottomNavigationBarItem(icon: Icon(Icons.check_circle), label: ''),
          BottomNavigationBarItem(icon: Icon(Icons.check_circle), label: ''),
          BottomNavigationBarItem(icon: Icon(Icons.check_circle), label: ''),
        ],
        currentIndex: _selectedIndex,
        selectedItemColor: const Color(0xFFFFA500),
        unselectedItemColor: Colors.grey, // 添加未选中颜色
        backgroundColor: Colors.white,
        type: BottomNavigationBarType.fixed, // 确保所有标签都可见
        showSelectedLabels: true, // 始终显示选中标签
        showUnselectedLabels: true, // 始终显示未选中标签
        selectedLabelStyle: const TextStyle(fontSize: 12.0),
        unselectedLabelStyle: const TextStyle(fontSize: 12.0),
        onTap: _onItemTapped,
      ),
    );
  }
}
